import { CartItem } from "@/types/cart";
import { httpRequest } from "@/utils/http";

// 添加商品至购物车API
export const postCartAPI = (data: { skuId: string, count: number }) => {
    return httpRequest({
        method: 'POST',
        url: '/member/cart',
        data,
    });
};

// 获取购物车的商品API
export const getCartAPI = () => {
    return httpRequest<CartItem[]>({
        method: 'GET',
        url: '/member/cart',
    });
};

// 删除购物车的商品API
export const deleteCartAPI = (data: { ids: string[] }) => {
    return httpRequest({
        method: 'DELETE',
        url: '/member/cart',
        data,
    });
};

// 按skuId修改购物车的商品信息
export const putCartBySkuIdAPI = (skuId: string, data: { selected?: boolean, count?: number }) => {
    return httpRequest({
        method: 'PUT',
        url: `/member/cart/${skuId}`,
        data,
    });
};

// 修改购物车全部商品选中状态
export const putAllCartSelectedAPI = (selected: boolean) => {
    return httpRequest({
        method: 'PUT',
        url: '/member/cart/selected',
        data: { selected },
    });
};